package com.yonyong.tao.commons.tasks;

import com.yonyong.tao.service.RunnerOneService;
import com.yonyong.tao.service.RunnerTwoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * @Describtion Todo
 * @Author yonyong
 * @Date 2020/3/28 12:36
 * @Version 1.0.0
 **/
@Component
@Slf4j
//@Transactional(rollbackFor = Exception.class)
public class MyTask {
     @Autowired
     RunnerOneService runnerOneService;
     @Autowired
    RunnerTwoService runnerTwoService;

    /**
     * 5s一次
     */
    @Scheduled(cron = "${mytask.task1}")
    public void runDevice() throws Exception {
        try {
            runnerOneService.runDevice();
        } catch (Exception e) {
            log.error(e.getMessage());
            throw new Exception("task1 run device fail...");
        }
    }

    /**
     * 5s一次
     */
    @Scheduled(cron = "${mytask.task1}")
    public void runEmployee() throws Exception {
        try {
            runnerOneService.runEmployee();
        } catch (Exception e) {
            log.error(e.getMessage());
            throw new Exception("task1 run employee fail...");
        }
    }

    /**
     * 5s一次
     */
    @Scheduled(cron = "${mytask.task1}")
    public void runDepartment() throws Exception {
        try {
            runnerOneService.runDepartment();
        } catch (Exception e) {
            log.error(e.getMessage());
            throw new Exception("task1 run department fail...");
        }
    }


    /**
     * 5s一次
     */
    @Scheduled(cron = "${mytask.task2}")
    public void runTaskTwo() throws Exception {
        try {
            runnerTwoService.run();
        } catch (Exception e) {
            log.error(e.getMessage());
            throw new Exception("task2 fail...");
        }
    }

}
